/**
 * Created by linyanbin on 2018/9/30.
 */
$(function(){
    var addUrl = '/campus/api/articles';
    var title = $('.compostion_title_parent input');
    var imgFile = $('.composition_img_parent input');
    var btn = $('button.composition_button');
    btn.click(function(){
        var formData = new FormData();
        formData.append('file', imgFile[0].files[0]);
        formData.append('articleTitle', title.val());
        formData.append('articleContent', editor.txt.html());
        $.ajax({
            url: addUrl,
            type: 'POST',
            data: formData,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    alert('发表成功,可进入个人中心查看!');
                    window.location.reload();
                }else {
                    alert('发表失败，请重试!');
                }
            }
        });
    });
});